home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-09 | 2.2 KB | 85 lines | [TEXT/GEOL] |
- Item forwarded by TIM.SWIHART to GARDNER.P
-
- Item 4466303 6-March-90 20:27PST
-
- From: V0645 Tandem, Gary Campbell,VAR
-
- To: MACDTS Macintosh Developer Tech. Supt.
-
- cc: CPLUS.DEV$ C++ Interest List--Developers
-
- Sub: re:CPLUS call by ref type err
-
- //
- // MPW 3.1
- // << CFront Version 1.0B1 (9/21/89; AT&T 2.0) ©Apple Computer, Inc. 1989 >>
-
- // CPLUS test program that because of the type mismatch between the function
- // 'increment', and the argument passed to it, a temporary lvalue is generated,
- // but the contents of the temporary never get put into the variable 'y', and
- // thus the call to 'increment' is a do nothing.
- //
- // CPLUS marks the offending line with the following warning that is hard to
- // understand,
- //
- // # warning: conversion of lvalue needed: temporary used to initialize
- reference
- //
- // and then generates code that doesn't get the temporary 'lvalue'
- // back into ( converted some how ) the call by reference paramenter.
- //
- // I would be happier with a type mismatch error if possible, rather than
- debugging
- // a run time error.
- //
- // the code generation looks funny, after the call to increment the next usage
- // of 'y' is pulled out of a register, but 'y' isn't passed via a register
- // since it is call by reference.
- //
- // ZORTECH gets the same error, sans the warning message, so this must be
- // related to CFRONT.
-
- //
- #include <stdio.h>
-
- void increment(long &x)
- {
- x++;
- }
- void test(long y)
- {
- if (y!=4) {
- printf("*** Error, y should be 4, instead y = %d\n",y);
- } else {
- printf("It worked, The value of y is %d\n",y);
- }
- }
-
- void main()
- {
-
- int y;
- long yl;
- //
- // test program that passes an 'int' to a 'long &' call by reference, by
- mistake
- // the warning message:
- // # warning: conversion of lvalue needed: temporary used to initialize
- reference
- // doesn't really tell you that the code being generated will not work
- // and this should really be some kind of type checking error
- //
- yl = 3;
- y = 3;
- increment(y);
- //
- // 'y' should be 4 now, right!
- // it would have been had 'y' been declared long.
- //
- test(y);
- increment(yl);
- test(yl);
-
- }
-
-